package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.domain.SLearningProgress;
import com.zhentao.domain.SLevel;
import com.zhentao.domain.SSubject;
import com.zhentao.domain.dto.LearningProgressParam;
import com.zhentao.domain.dto.LevelSubjectDto;
import com.zhentao.domain.dto.SubjectParam;
import com.zhentao.mapper.SLearningProgressMapper;
import com.zhentao.mapper.SSubjectMapper;
import com.zhentao.result.Result;
import com.zhentao.service.SLevelService;
import com.zhentao.mapper.SLevelMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author 86150
* @description 针对表【s_level】的数据库操作Service实现
* @createDate 2024-07-23 11:12:37
*/
@Service
public class SLevelServiceImpl extends ServiceImpl<SLevelMapper, SLevel>
    implements SLevelService {


    @Resource
    private SLevelMapper sLevelMapper;

    @Resource
    private SSubjectMapper sSubjectMapper;

    @Resource
    private SLearningProgressMapper sLearningProgressMapper;

    //获取课程信息
    @Override
    public List<LevelSubjectDto> getSubjectList() {
        //查询所有的阶段
        List<SLevel> list = sLevelMapper.selectList(null);
        //创建一个集合，查询阶段下所有的学习阶段
        List<LevelSubjectDto> dtoList = new ArrayList<>();
        //遍历阶段
        for (SLevel sLevel : list) {
            //创建LevelSubjectDto对象
            LevelSubjectDto subjectDto = new LevelSubjectDto();
            subjectDto.setValue(sLevel.getId().toString());
            subjectDto.setLabel(sLevel.getLevelName());
            List<SLearningProgress> list2 = sLearningProgressMapper.selectList(Wrappers.<SLearningProgress>lambdaQuery().eq(SLearningProgress::getLevelId, sLevel.getId()));
            List<LearningProgressParam> list3 = new ArrayList<>();
            for (SLearningProgress sLearningProgress : list2) {
                //创建LearningProgressParam对象
                LearningProgressParam learningProgressParam = new LearningProgressParam();
                learningProgressParam.setValue(sLearningProgress.getId().toString());
                learningProgressParam.setLabel(sLearningProgress.getName());
                List<SSubject> list4 = sSubjectMapper.selectList(Wrappers.<SSubject>lambdaQuery().eq(SSubject::getLpId, sLearningProgress.getId()));
                List<SubjectParam> list5 = new ArrayList<>();
                for (SSubject subject : list4) {
                    //创建SubjectParam对象
                    SubjectParam subjectParam = new SubjectParam();
                    subjectParam.setValue(subject.getId().toString());
                    subjectParam.setLabel(subject.getSubjectName());
                    list5.add(subjectParam);
                }
                learningProgressParam.setChildren(list5);
                list3.add(learningProgressParam);
            }
            subjectDto.setChildren(list3);
            dtoList.add(subjectDto);
        }
        return dtoList;
    }


}

